home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-04 | 4.2 KB | 105 lines | [TEXT/GEOL] |
- Item 9478958 1-May-90 15:21PDT
-
- From: D5284 BDM Int'l, Ann Confer,PRT
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: Clearing the Clipboard
-
- We are developing a MacApp application that must clear the contents of the
- clipboard whenever the application is Quit. Although this is not a common
- practive in Macintosh applications it is being done at the request of the
- customer. When switching between open application in MultiFinder, the contents
- are not to be cleared.
-
- The problem sounds simple but has not been easy to solve. I have managed t
- get it to work in a particular scenario but in another. If I perform a Copy
- from within my application, switch to another application (to paste, for
- example), switch back to my application, and then quit, the system clipboard is
- not cleared. However, if I perform a second copy operation after switching
- back, and then quit, the system clipboard is cleared. Regardless of the
- mechanism I try for clearing the clipboard, these scenarios remain the same.
- Is there something basic that I am overlooking that prohibits me from doing
- this?
-
- I have tried two basic approaches. First of all, I tried using the Toolbox
- calls ZeroScrap, PutScrap, etc directly. As the very last line(s) in the main
- program of the MacApp application, I tried calling ZeroScrap and then inserting
- nothing or blanks into the Clipboard. This did not work. I also tried adding
- such calls in overridden versions of methods such as the MainEventLoop. I even
- tried setting the scrap state parameter to not initialized.
-
- Currently (see below), I have overridden TApplication.MainEventLoop to perfo
- all of the normal event loop processing and then to call my ClearClipboard
- procedure. This procedure creates a new empty view and assigns it to
- gClipView. Then when AboutToLoseControl is called, my empty view is written to
- the desk scrap. Unfortunately, this only works if a copy is done after
- reentering my application (as described above). I tried mimicing the
- operations performed by a copy command in ClearClipboard and then creating my
- empty clipboard view, but there was no difference.
-
-
- If anyone has any ideas, I would appreciate it. Thanks. Ann Confer
-
-
-
-
- (* Here is the ClearClipboard procedure called from MainEventLoop Not all
- attempts are included here; only the most recent version. Sorry that the format
- got messed up when I copied it in here. *)
-
- PROCEDURE ClearClipboard;
-
- VAR theScrapPtr: PScrapStuff; (* old *)
- theScrap: ScrapStuff;
- blank, theString: Str255;
- emptyClipView: TTEView;
- theHandle: Handle;
- acommand: TCutCopyCommand;
-
- (* begin ClearClipboard *)
- BEGIN
- {$IFC qDebug}writeln('***Entering ClearClipboard');{$ENDC}
-
- (* new attempt to mimic copy command - no diff *)
- IF (gLastCommand = NIL) THEN
- BEGIN
- New(emptyClipView);
- FailNIL(emptyClipView);
- emptyClipView.ITEView(NIL, NIL,gZeroVPt, gZeroVPt,sizeFixed, sizeFixed,
- gZeroRect,gSystemStyle,teJustLeft,kWithoutStyle, TRUE);
- emptyClipView.fAcceptsChanges := FALSE;
- acommand := emptyClipView.DoMakeEditCommand(cCopy);
- acommand.DoIt;
- END; (* end code for new attempt - no diff *)
-
- (* commit the last clipboard-related command so the application wont writ
- "old" data to the clipboard when application is processed by
- AboutToLoseControl *)
- IF (gLastCommand <> NIL) & (gLastCommand.fChangesClipboard) THEN
- gAnalysisApplication.CommitLastCommand;
- (* create an empty clipboard view *)
- New(emptyClipView);
- FailNIL(emptyClipView);
- emptyClipView.ITEView(NIL, NIL,gZeroVPt, gZeroVPt,sizeFixed, sizeFixed,
- gZeroRect,gSystemStyle,teJustLeft,kWithoutStyle, TRUE);
- emptyClipView.fAcceptsChanges := FALSE;
-
- (* invoke TTEView.StuffText to stuff empty text handle into the view *)
- (* ** tried setting handle to blanks rather than empty, no diff *)
- theHandle := NewPermHandle(0);
- FailNil(theHandle);
- theString := ' ';
- (* invoke Mac OS Utility PtrAndHand to append the string to the view text *)
- FailOSErr(PtrAndHand(@theString[1], theHandle, Length(theString) ));
- emptyClipView.StuffText(theHandle);
- gAnalysisApplication.ClaimClipboard(emptyClipView);
- gClipWrittenToDeskScrap := FALSE;
-
- {$IFC qDebug} writeln('***Exiting ClearClipboard');{$ENDC}
-
- (* end ClearClipboard *)
- END;
-
-
-